﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyMovieInfo
{
    public class NetflixLookup : IMovieLookup
    {
        public Movie GetMovieDetails(string name, int? year, string file)
        {
            //hit the odata feed for netflix.
            var catalog = new NetflixService.NetflixCatalog(
                new Uri("http://odata.netflix.com/Catalog/",
                    UriKind.Absolute));

            var response = (from p in catalog.Titles
                            where p.Name == name
                                && p.ReleaseYear == year
                                && p.ShortSynopsis != null
                            select p).Take(1);

            var movie = new Movie() { Name=name, Year=year };
            if (response.Count() == 1)
            {
                var title = response.Single<NetflixService.Title>();
                movie.Year = year;
                movie.MatchFound = true;
                movie.Name = title.Name;
                movie.CoverURL = title.BoxArt.LargeUrl;
                movie.Synopsis = title.ShortSynopsis;
                movie.Source = "NetFlix";
            }
            else
            {
                movie.MatchFound = false;
            }

            return movie;

        }

    }
}
